package com.bigModel.backend.controller.Device;

import com.bigModel.backend.advice.ResponseNotIntercept;
import com.bigModel.backend.advice.result.Result;
import com.bigModel.backend.pojo.DeviceInfo;
import com.bigModel.backend.service.Device.DeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.bigModel.backend.advice.result.Result.failed;
import static com.bigModel.backend.advice.result.Result.success;

@ResponseNotIntercept
@RestController
public class DeviceInfoController {
    @Autowired
    private DeviceInfoService deviceInfoService;
    @GetMapping("/device/info")
    public Result getDeivcelistAll(){
        return success(deviceInfoService.getDeivcelistAll());
    }

    @GetMapping("/device/info/{id}")
    public Result<DeviceInfo> getDeviceInfoById(@PathVariable int id){
        // 查询单个设备信息
        DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(id);
        return success(deviceInfo);
    }
    @PostMapping("/device/add")
    public Result addDeviceInfo(@RequestBody DeviceInfo deviceInfo){
        int result = deviceInfoService.addDeviceInfo(deviceInfo);
        if(result==0){
            return Result.failed("添加失败");
        }
        return Result.success("添加成功");
    }
    @PostMapping("/device/delete")
    public Result deleteDeviceInfo(@RequestBody DeviceInfo deviceInfo){
        int result = deviceInfoService.deleteDeviceInfo(deviceInfo);
        if(result==0){
            return Result.failed("删除失败");
        }
        return Result.success("删除成功");
    }
}
